package objectOutputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        //一次写入多个对象
        //1.创建序列化流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("IODemo\\user.txt"));
        //2.写入多个数据
        //2.1将多个对象添加到集合中进行写入比较方便
        ArrayList<User> list = new ArrayList<>();
        User u1 = new User("jack",22);
        User u2 = new User("tom",22);
        User u3 = new User("kk",22);
        list.add(u1);
        list.add(u2);
        list.add(u3);
        //2.2将集合写入
        oos.writeObject(list);
        //3.释放资源
        oos.close();
    }
}
